package com.yrk.service.impl;

import com.yrk.entity.User;
import com.yrk.mapper.UserMapper;
import com.yrk.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    //注册
    @Override
    public int registerUser(User user) {
        int num=userMapper.registerUser(user);
        return num;
    }
    //登录
    @Override
    public User loginUser(User user) {
        User user1=userMapper.loginUser(user);
        return user1;
    }
    //添加功能
    @Override
    public int addUser(User user) {
        return userMapper.addUser(user);
    }
    //删除
    @Override
    public int deleteUser(User user) {
        return userMapper.deleteUser(user);
    }
//修改
    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }
    //查询
    @Override
    public List<User> getUserList() {
        return userMapper.getUserList();
    }
//模糊查询
    @Override
    public List<User> findUserByVague(String vague) {
        return userMapper.findUserByVague(vague);
    }

    @Override
    public int deleteInBulkUser(List<Integer> userList) {
        return userMapper.deleteInBulkUser(userList);
    }

    @Override
    public Map<String,Object> findUserPage(Map<String, Integer> map) {
        int pageNum = map.get("pageNum");
        int pageSize = map.get("pageSize");
        map.put("pageNum", (pageNum-1)*pageSize);
        List<User> list=userMapper.findUserPage(map);
        int count=userMapper.selectUserCount();
        int totalPage=count%pageSize==0?count/pageSize:count/pageSize+1;
        Map<String,Object> map1=new HashMap<>();
        map1.put("totalPage", totalPage);
        map1.put("pageNum",pageNum);
        map1.put("list",list);
        map1.put("pageSize",pageSize);
        return map1;
    }

}
